package com.Service;

import cn.hutool.core.util.NumberUtil;
import com.Bean.Good;
import com.Bean.PurchaseOrder;
import com.Bean.SealOrder;
import com.Common.CodeMsg;
import com.Common.PageInfo;
import com.Common.Result;
import com.Dao.SealOrderDao;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: hkw14
 * @time: 2021/5/6 20:47
 */
public class SealOrderService {
    SealOrderDao sealOrderDao = new SealOrderDao();
    public Result queryPage(Map<String, Object> params, String page, String limit) {
        Integer pageNo =  NumberUtil.isNumber(page)?Integer.parseInt(page):1;
        Integer pageSize =  NumberUtil.isNumber(limit)?Integer.parseInt(limit):10;
        PageInfo<SealOrder> pageInfo = sealOrderDao.selectPage(params, pageNo, pageSize);
        return new Result(pageInfo);
    }

    public Result deleteOrder(String... ids) {
        boolean flag = sealOrderDao.batchDelete(ids);
        return flag?new Result():new Result(CodeMsg.GOOD_DELETE_ERROR);
    }

    public Result addOrder(Integer goodID, Integer userID, String goodName, Integer number, String userName, BigDecimal unitPrice){
        boolean add = sealOrderDao.add(goodID, userID, goodName, number, userName, unitPrice);
        if (add){
            return new Result();
        }
        return new Result(CodeMsg.ORDER_ADD_ERROR);
    }
    @Test
    public void test(){
        SealOrderService purchaseOrderService = new SealOrderService();
        Map<String,Object> params = new HashMap<String,Object>();
        Result result = purchaseOrderService.queryPage(params, null, null);
        PageInfo data = (PageInfo)result.getData();
        List list = data.getList();
        System.out.println(data.getCount());
        Iterator<SealOrder> iterator = list.iterator();

        while (iterator.hasNext()){
            SealOrder next = iterator.next();
            System.out.println(next);
        }
    }

    @Test
    public void test2(){
        SealOrderService purchaseOrderService = new SealOrderService();
    }
}
